<?php

namespace app\test512\model;

use think\Model;

class Base extends Model
{
    //无限极分类
    public function get_tree_list($data, $pid = 0, $html = "--", $level = 1)
    {
        //定义静态空数组
        static $arr = [];

        //循环权限的数据
        foreach ($data as $v) {
            //判断pid 是否等于$pid 等于则为顶级
            if ($v['pid'] == $pid) {
                $v['html'] = str_repeat($html, $level);
                $v['level'] = $level + 1;
                $arr[] = $v;

                $this->get_tree_list($data, $v['id'], $html, $v['level']);
            }
        }
        return $arr;
    }


    //无限极分类 权限层级展示
    public function sonlevel($data, $pid = 0)
    {
        //定义空数组
        $arr = [];

        //循环权限的数据
        foreach ($data as $v) {
            //判断pid 是否等于$pid 等于则为顶级
            if ($v['pid'] == $pid) {
                $v['son'] = $this->sonlevel($data, $v['id']);
                $arr[] = $v;
            }
        }
        return $arr;
    }
}
